﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Dungeon_Dive
{
    /// <summary>
    /// Screen for displaying help text.
    /// </summary>
    public class HelpScreen : GameScreen
    {
        // Help screen is pretty rudimentary. Should be fancified if time permits.

        SpriteBatch sb;
        SpriteFont font;

        private Log log;        

        public HelpScreen(Game1 game)
            : base(game)
        {
        }

        /// <summary>
        /// Initialize Help Screen.
        /// </summary>
        public override void Initialize()
        {
            log = (Log)parentGame.Services.GetService(typeof(Log));
            log.Write("HelpScreen.Init()");
            base.Initialize();
        }

        protected override void LoadContent()
        {
            log.Write("HelpScreen.LoadContent()");
            ContentManager contentManager = (ContentManager)parentGame.Services.GetService(typeof(ContentManager));
            sb = contentManager.SpriteBatch;            
            font = contentManager.Font;
            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        /// <summary>
        /// Draws help text on the screen.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            // Probably should read help text from a file.            

            int blockstart = 10;
            int ls = font.LineSpacing;

            sb.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront,
                SaveStateMode.SaveState);
            sb.DrawString(font, "In Dungeon Dive you take on the role of an adventurer braving a perilous dungeon.",
                new Vector2(10, blockstart), Color.White);
            sb.DrawString(font, "Your objective is to reach the bottom of the dungeon.",
                new Vector2(10, blockstart + ls), Color.White);
            sb.DrawString(font, "You descend by means of portals somewhere on each level. You can only ever go down.",
                new Vector2(10, blockstart + ls*2), Color.White);
            sb.DrawString(font, "You can see the number of the level your character is on in the upper right corner.",
                new Vector2(10, blockstart + ls*3), Color.White);

            blockstart = blockstart + ls * 5;

            sb.DrawString(font, "Choosing \"Continue\" from Main Menu will load your most recent game in progress.",
                new Vector2(10, blockstart), Color.White);
            sb.DrawString(font, "\"Start New Game\" will begin a new game with your character at the top of the dungeon.",
                new Vector2(10, blockstart + ls), Color.White);
            sb.DrawString(font, "If you don't have a saved game, \"Continue\" will function like \"Start New Game\".",
                new Vector2(10, blockstart + ls*2), Color.White);

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "You move your character around with 'W','A','S' and 'D' keys and turn with the mouse.",
                new Vector2(10, blockstart), Color.White);
            sb.DrawString(font, "You attack with left mouse button. Pressing \"Esc\" will bring up Pause Menu.",
                new Vector2(10, blockstart + ls), Color.White);                        
            sb.DrawString(font, "From Pause Menu you can view this Help text or \"Save and Quit\" if you need a break.",
                new Vector2(10, blockstart + ls * 2), Color.White);

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "In the dungeons you will encounter monsters which will try to attack you.",
                new Vector2(10, blockstart), Color.White);
            sb.DrawString(font, "When hit, you will lose elemental tokens. When you lose all, you die.",
                new Vector2(10, blockstart + ls), Color.White);
            sb.DrawString(font, "Your current elemental tokens are displayed in the lower right corner of the screen.",
                new Vector2(10, blockstart + ls * 2), Color.White);
            sb.DrawString(font, "You can get more from the enemies you vanquish. Try to collect at least three of a type.",
                new Vector2(10, blockstart + ls * 3), Color.White);
            sb.DrawString(font, "Doing so will replace your standard attack with a more powerful elemental attack.",
                new Vector2(10, blockstart + ls * 4), Color.White);
            sb.DrawString(font, "Be careful. The more powerful monsters will have elemental attacks themselves.",
                new Vector2(10, blockstart + ls * 5), Color.White);

            blockstart = blockstart + ls * 7;

            sb.DrawString(font, "On certain levels you will find special portals that mark milestones in your quest.",
                new Vector2(10, blockstart), Color.White);
            sb.DrawString(font, "Once passed these portals will show up on the starting level in all subsequent games.",
                new Vector2(10, blockstart + ls), Color.White);
            sb.DrawString(font, "They act as shortcuts that take you deeper into the dungeon.",
                new Vector2(10, blockstart + ls * 2), Color.White);

            blockstart = Game.Window.ClientBounds.Height - ls;
            int cx = (int)(Game.Window.ClientBounds.Width / 2 - font.MeasureString("Press Spacebar to continue.").X / 2);

            sb.DrawString(font, "Press Spacebar to continue.",
                new Vector2(cx, blockstart), Color.White);
            sb.End();

            base.Draw(gameTime);
        }
    }
}